import 'package:flutter/material.dart';

/// 通用错误视图组件
class ErrorView extends StatelessWidget {
  /// 错误消息
  final String errorMessage;

  /// 重试回调
  final VoidCallback? onRetry;

  /// 图标
  final IconData icon;

  /// 图标颜色
  final Color iconColor;

  const ErrorView({
    Key? key,
    required this.errorMessage,
    this.onRetry,
    this.icon = Icons.error_outline,
    this.iconColor = Colors.red,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(icon, size: 64, color: iconColor),
          const SizedBox(height: 16),
          Text(
            errorMessage,
            textAlign: TextAlign.center,
            style: TextStyle(color: iconColor),
          ),
          if (onRetry != null) ...[
            const SizedBox(height: 16),
            ElevatedButton(onPressed: onRetry, child: const Text('重试')),
          ],
        ],
      ),
    );
  }
}
